package com.seckill.page.controller;

import com.seckill.goods.pojo.Sku;
import com.seckill.page.service.ItemPageService;
import com.seckill.util.Result;
import com.seckill.util.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: seckill-parent
 * @description: 商品页面的控制器
 * @author: zhanghz001
 * @create: 2021-06-25 09:46
 **/
// @RestController
@RequestMapping("/page")

public class ZhzSkuPageController {
    @Autowired
    private ItemPageService itemPageService;
    
    @PostMapping("/html")
    public Result writePage(@RequestBody Sku sku) throws Exception {
        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("templateName", "1.ftl");
        dataMap.put("filename", sku.getId() + ".html");
        itemPageService.createHtml(dataMap);
        return new Result(true, StatusCode.OK, "生成静态页面成功");
    }
    
    @DeleteMapping("/html/{id}")
    public Result delete(@PathVariable(value = "id") String id) throws Exception {
        itemPageService.delete(id + ".html");
        return new Result(true, StatusCode.OK, "删除静态页面成功!");
    }
}
